package com.etool.modules.curd.util;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import com.etool.modules.curd.service.CurdService;

public class CurdConfigUtil {
	
	
	public static void setSecondJdbc(CurdService curdService,String target)
	{
		List<Map<String, Object>> curdConfig= curdService.read("curd_config", Collections.singletonMap("tableName",(Object)target));
		if(curdConfig!=null && curdConfig.size()==1)
		{
			WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext(); 
			NamedParameterJdbcTemplate jdbc=(NamedParameterJdbcTemplate) context.getBean((String)curdConfig.get(0).get("jdbc"));
			curdService.setSecondJdbc(jdbc);
		}
		
	}
	
	public static void disableSecondJdbc(CurdService curdService)
	{
		curdService.disableSecondJdbc();
	}

	
}
